<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <HomeCategory />
        <!-- banner轮播图 -->
        <HomeBanner />
        <HomePanel title="新鲜好物"
                   subTitle="新鲜出炉 品质靠谱">
          <template #right>
            <XtxMore></XtxMore>
          </template>
          <template #main>
            <ul ref="pannel"
                class="goods-list">
              <li v-for="item in newList"
                  :key="item.id">
                <RouterLink :to="`/detail/${item.id}`">
                  <img :src="item.picture"
                       alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePanel>
        <HomePanel title="人气推荐"
                   subTitle="人气爆款 不容错过">
          <template #main>
            <ul ref="pannel"
                class="goods-list">
              <li v-for="item in hotList"
                  :key="item.id">
                <RouterLink to="/">
                  <img v-img-lazy='item.picture'
                       alt="" />
                  <p class="name">{{ item.title }}</p>
                  <p class="desc">{{ item.alt }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePanel>
        <HomePanel title="热门品牌"
                   subTitle="国际经典 品质保证">
          <template #main>
            <ul ref="pannel"
                class="brand-list">
              <li v-for="item in BrandList"
                  :key="item.id">
                <RouterLink to="/">
                  <img v-img-lazy='item.picture'
                       alt="" />
                </RouterLink>
              </li>
            </ul>
          </template>
        </HomePanel>
      </div>
    </div>
  </div>
</template>

<script>
import HomeCategory from './components/home-categroy.vue'
import HomeBanner from './components/home-banner'
import HomePanel from './components/home-panel.vue'
import { findNew, findHot, findBrand } from '@/api/Home.js'
import { ref } from 'vue'
export default {
  name: 'xtx-home-page',
  components: {
    HomeCategory,
    HomeBanner,
    HomePanel
  },
  setup () {
    // 新鲜好物数据
    const newList = ref([])
    const loadNewList = async () => {
      const res = await findNew()
      newList.value = res.result
    }
    loadNewList()

    // 人气推荐数据
    const hotList = ref([])
    const loadHotList = async () => {
      const res = await findHot()
      console.log(res)
      hotList.value = res.result
    }
    loadHotList()
    // 热门品牌数据
    const BrandList = ref([])
    const loadBrandList = async () => {
      const res = await findBrand()
      console.log(res)
      BrandList.value = res.result
    }
    loadBrandList()
    return {
      newList,
      hotList,
      BrandList
    }
  }
}
</script>

<style scoped lang='less'>
.brand-list{
  display: flex;
  li{
    flex:1;
    padding: 10px;
  }
}
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
    .desc {
      color: #999;
      font-size: 18px;
    }
  }
}
</style>
